<template>
  <!-- 一条文章单元格 -->
 <div>
    <van-cell>
      <!-- 标题区域的插槽 -->
      <template #title>
        <div class="title-box">
          <!-- 标题 -->
          <span>{{ artObj.title }}</span>
          <!-- 单图 -->
          <img
            v-if="artObj.cover.type === 1"
            class="thumb"
            alt=""
            v-lazy="artObj.cover.images[0]"
          />
          <!-- <van-image
            v-if="artObj.cover.type === 1"
            class="thumb"
            :src='artObj.cover.images[0]'
            alt=""
          >
         <template v-slot:err>图片走丢了</template>
          </van-image> -->
        </div>
        <!-- 多图 -->
        <div class="thumb-box" v-if="artObj.cover.type > 1">
          <img
            v-for="(imgUrl, index) in artObj.cover.images"
            :key="index"
            class="thumb"
            v-lazy='imgUrl'
            alt=""
          />
          <!-- <van-image
            v-for="(imgUrl, index) in artObj.cover.images"
            :key="index"
            class="thumb"
            v-lazy="imgUrl"
            alt=""
          >
            <template v-slot:error>图片走丢了</template>
          </van-image> -->
        </div>
      </template>
      <!-- label 区域的插槽 -->
      <template #label>
        <div class="label-box">
          <div>
            <span>{{ artObj.aut_name }}</span>
            <span>{{ artObj.comm_count }} 评论</span>
            <span>{{ formatTime(artObj.pubdate)  }}</span>
            <!-- 反馈按钮 -->
          <van-icon name="cross" @click.stop="show=true" class="cross" v-if="isShow"/>
          </div>

        </div>
      </template>
    </van-cell>
    <van-action-sheet v-model="show"
    :actions="actions"
     @select="onSelect"
     @cancel="cancelFn"
     @close='closeFn'
     get-container="body"
     :cancel-text="bottomText"
     />
 </div>
</template>
<script>
// 1. 点击<反馈垃圾内容>切换actions数据为secondActions
// 2. 下面文字显示返回
// 3. 点击返回(不能关闭), 而是切换actions数据为firstActions
// 4. 下面文字显示取消

import { firstActions, secondActions } from '@/api/report'
import { timeAgo } from '@/utils/date.js'
export default {
  props: {
    artObj: Object,
    isShow: {
      type: Boolean,
      default: true
    }
  },
  data () {
    return {
      show: false,
      actions: firstActions,
      bottomText: '取消'

    }
  },
  methods: {
    formatTime: timeAgo, // 函数体是timeAgo
    onSelect (action) {
      // 默认情况下点击选项时不会自动收起
      // 可以通过 close-on-click-action 属性开启自动收起
      // this.show = false
      if (action.name === '反馈垃圾内容') {
        // 证明点击的是反馈垃圾内容
        this.actions = secondActions
        this.bottomText = '返回'
      } else if (action.name === '不感兴趣') {
        this.$emit('disLikeEV', this.artObj.art_id)
        this.show = false // 无论成功还是失败，关闭面板
      } else {
        // 在这里不是以上两种情况，直接进入的就是二级面板
        this.$emit('feedBackEV', this.artObj.art_id, action.value)
        this.actions = firstActions
        this.show = false
      }
    },
    // 底部按钮点击事件
    cancelFn () {
      if (this.bottomText === '返回') {
        this.show = true
        this.actions = firstActions
        this.bottomText = '取消'
      }
    },
    // 关闭面板触发事件
    closeFn () {
      this.actions = firstActions
      this.bottomText = '取消'
    }
  }

}
</script>
<style lang="less">
/* 图片的样式, 矩形黄金比例：0.618 */
.thumb {
  width: 113px;
  height: 70px;
  background-color: #f8f8f8;
  object-fit: cover;
}

/* 三图, 图片容器 */
.thumb-box {
  display: flex;
  justify-content: space-between;
}
.cross{
  padding-left: 200px;
}
</style>
